<?php


namespace Frieza\Modules\RiskContent\Actions;

use Doraemon\cache\ToBan;
use Doraemon\model\AdmOperateLog;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class Ignore extends RowAction
{
    public $name = '忽略';
    const TOAST_ALERT = '你确定要忽略此用户吗？';

    public function handle($uid)
    {
        $admin_id = Admin::user()->id;
        $admin_name = Admin::user()->username;
        $res = ToBan::setUid(ToBan::IGNORE_BAN.$uid, $uid,7*86400);
        if ($res) {
            AdmOperateLog::addLog($uid,AdmOperateLog::$operate_type['igonre'],$admin_id,$admin_name);
            return $this->response()->success('已忽略该用户')->refresh();
        } else {
            return $this->response()->error('操作失败,稍后重试!');
        }


    }

    public function retrieveModel(Request $request)
    {
        if (!$key = $request->get('_key')) {
            return false;
        }

        return $key;
    }

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}